package org.saxonextensions.eml.emitter;

import javax.mail.internet.MimeMessage;
import javax.mail.*;
import javax.mail.search.SearchTerm;
import javax.activation.DataHandler;
import java.util.Date;
import java.util.Enumeration;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * Mime Message wrapper, adding a getter method for a mail session.
 *
 * @author Ivan Latysh
 * @since 14-Jan-2009 1:30:21 PM
 */
public class MimeMessageWrapper {

  /** MimeMessage */
  private MimeMessage message;
  /** Mail session */
  private Session session;

  public MimeMessageWrapper(Session session) {
    this.session = session;
    message = new MimeMessage(session);
  }

  public MimeMessageWrapper(Session session, InputStream is) throws MessagingException {
    this.session = session;
    message = new MimeMessage(session, is);
  }

  public MimeMessageWrapper(MimeMessageWrapper source) throws MessagingException {
    this.session = source.getSession();
    message = new MimeMessage(source.getMessage());
  }

  public MimeMessage getMessage() {
    return message;
  }

  public Session getSession() {
    return session;
  }

  public Address[] getFrom() throws MessagingException {
    return message.getFrom();
  }

  public void setFrom(Address address) throws MessagingException {
    message.setFrom(address);
  }

  public void setFrom() throws MessagingException {
    message.setFrom();
  }

  public void addFrom(Address[] addresses) throws MessagingException {
    message.addFrom(addresses);
  }

  public Address getSender() throws MessagingException {
    return message.getSender();
  }

  public void setSender(Address address) throws MessagingException {
    message.setSender(address);
  }

  public Address[] getRecipients(Message.RecipientType recipientType) throws MessagingException {
    return message.getRecipients(recipientType);
  }

  public Address[] getAllRecipients() throws MessagingException {
    return message.getAllRecipients();
  }

  public void setRecipients(Message.RecipientType recipientType, Address[] addresses) throws MessagingException {
    message.setRecipients(recipientType, addresses);
  }

  public void setRecipients(Message.RecipientType recipientType, String s) throws MessagingException {
    message.setRecipients(recipientType, s);
  }

  public void addRecipients(Message.RecipientType recipientType, Address[] addresses) throws MessagingException {
    message.addRecipients(recipientType, addresses);
  }

  public void addRecipients(Message.RecipientType recipientType, String s) throws MessagingException {
    message.addRecipients(recipientType, s);
  }

  public Address[] getReplyTo() throws MessagingException {
    return message.getReplyTo();
  }

  public void setReplyTo(Address[] addresses) throws MessagingException {
    message.setReplyTo(addresses);
  }

  public String getSubject() throws MessagingException {
    return message.getSubject();
  }

  public void setSubject(String s) throws MessagingException {
    message.setSubject(s);
  }

  public void setSubject(String s, String s1) throws MessagingException {
    message.setSubject(s, s1);
  }

  public Date getSentDate() throws MessagingException {
    return message.getSentDate();
  }

  public void setSentDate(Date date) throws MessagingException {
    message.setSentDate(date);
  }

  public Date getReceivedDate() throws MessagingException {
    return message.getReceivedDate();
  }

  public int getSize() throws MessagingException {
    return message.getSize();
  }

  public int getLineCount() throws MessagingException {
    return message.getLineCount();
  }

  public String getContentType() throws MessagingException {
    return message.getContentType();
  }

  public boolean isMimeType(String s) throws MessagingException {
    return message.isMimeType(s);
  }

  public String getDisposition() throws MessagingException {
    return message.getDisposition();
  }

  public void setDisposition(String s) throws MessagingException {
    message.setDisposition(s);
  }

  public String getEncoding() throws MessagingException {
    return message.getEncoding();
  }

  public String getContentID() throws MessagingException {
    return message.getContentID();
  }

  public void setContentID(String s) throws MessagingException {
    message.setContentID(s);
  }

  public String getContentMD5() throws MessagingException {
    return message.getContentMD5();
  }

  public void setContentMD5(String s) throws MessagingException {
    message.setContentMD5(s);
  }

  public String getDescription() throws MessagingException {
    return message.getDescription();
  }

  public void setDescription(String s) throws MessagingException {
    message.setDescription(s);
  }

  public void setDescription(String s, String s1) throws MessagingException {
    message.setDescription(s, s1);
  }

  public String[] getContentLanguage() throws MessagingException {
    return message.getContentLanguage();
  }

  public void setContentLanguage(String[] strings) throws MessagingException {
    message.setContentLanguage(strings);
  }

  public String getMessageID() throws MessagingException {
    return message.getMessageID();
  }

  public String getFileName() throws MessagingException {
    return message.getFileName();
  }

  public void setFileName(String s) throws MessagingException {
    message.setFileName(s);
  }

  public InputStream getInputStream() throws IOException, MessagingException {
    return message.getInputStream();
  }

  public InputStream getRawInputStream() throws MessagingException {
    return message.getRawInputStream();
  }

  public DataHandler getDataHandler() throws MessagingException {
    return message.getDataHandler();
  }

  public Object getContent() throws IOException, MessagingException {
    return message.getContent();
  }

  public void setDataHandler(DataHandler dataHandler) throws MessagingException {
    message.setDataHandler(dataHandler);
  }

  public void setContent(Object o, String s) throws MessagingException {
    message.setContent(o, s);
  }

  public void setText(String s) throws MessagingException {
    message.setText(s);
  }

  public void setText(String s, String s1) throws MessagingException {
    message.setText(s, s1);
  }

  public void setText(String s, String s1, String s2) throws MessagingException {
    message.setText(s, s1, s2);
  }

  public void setContent(Multipart multipart) throws MessagingException {
    message.setContent(multipart);
  }

  public Message reply(boolean b) throws MessagingException {
    return message.reply(b);
  }

  public void writeTo(OutputStream outputStream) throws IOException, MessagingException {
    message.writeTo(outputStream);
  }

  public void writeTo(OutputStream outputStream, String[] strings) throws IOException, MessagingException {
    message.writeTo(outputStream, strings);
  }

  public String[] getHeader(String s) throws MessagingException {
    return message.getHeader(s);
  }

  public String getHeader(String s, String s1) throws MessagingException {
    return message.getHeader(s, s1);
  }

  public void setHeader(String s, String s1) throws MessagingException {
    message.setHeader(s, s1);
  }

  public void addHeader(String s, String s1) throws MessagingException {
    message.addHeader(s, s1);
  }

  public void removeHeader(String s) throws MessagingException {
    message.removeHeader(s);
  }

  public Enumeration getAllHeaders() throws MessagingException {
    return message.getAllHeaders();
  }

  public Enumeration getMatchingHeaders(String[] strings) throws MessagingException {
    return message.getMatchingHeaders(strings);
  }

  public Enumeration getNonMatchingHeaders(String[] strings) throws MessagingException {
    return message.getNonMatchingHeaders(strings);
  }

  public void addHeaderLine(String s) throws MessagingException {
    message.addHeaderLine(s);
  }

  public Enumeration getAllHeaderLines() throws MessagingException {
    return message.getAllHeaderLines();
  }

  public Enumeration getMatchingHeaderLines(String[] strings) throws MessagingException {
    return message.getMatchingHeaderLines(strings);
  }

  public Enumeration getNonMatchingHeaderLines(String[] strings) throws MessagingException {
    return message.getNonMatchingHeaderLines(strings);
  }

  public Flags getFlags() throws MessagingException {
    return message.getFlags();
  }

  public boolean isSet(Flags.Flag flag) throws MessagingException {
    return message.isSet(flag);
  }

  public void setFlags(Flags flags, boolean b) throws MessagingException {
    message.setFlags(flags, b);
  }

  public void saveChanges() throws MessagingException {
    message.saveChanges();
  }

  public void setRecipient(Message.RecipientType recipientType, Address address) throws MessagingException {
    message.setRecipient(recipientType, address);
  }

  public void addRecipient(Message.RecipientType recipientType, Address address) throws MessagingException {
    message.addRecipient(recipientType, address);
  }

  public void setFlag(Flags.Flag flag, boolean b) throws MessagingException {
    message.setFlag(flag, b);
  }

  public int getMessageNumber() {
    return message.getMessageNumber();
  }

  public Folder getFolder() {
    return message.getFolder();
  }

  public boolean isExpunged() {
    return message.isExpunged();
  }

  public boolean match(SearchTerm searchTerm) throws MessagingException {
    return message.match(searchTerm);
  }
}
